package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.heima.common.dto.ResponseResult;
import com.heima.media.service.IWmChannelService;
import com.heima.media.Dto.ChannleDto;
import com.heima.media.entity.WmChannel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {

    @Autowired
    IWmChannelService wmChannelService;
    /**
     * 根据名称分页查询
     */
    @PostMapping("/list")
    @ApiOperation(value = "根据名称模糊查询分页列表",notes = "author:lyd")
    @ApiImplicitParam(name = "dto", value = "查询对象", required = true,dataType = "ChannleDto")
    public ResponseResult listByName(@RequestBody ChannleDto dto){
        return wmChannelService.listByName(dto);
    }

    @GetMapping("/channels")
    public ResponseResult listChannels(){
        LambdaQueryWrapper<WmChannel> query = new LambdaQueryWrapper<>();
        query.orderByAsc(WmChannel::getId);
        List<WmChannel> list = wmChannelService.list(query);
        return ResponseResult.okResult(list);
    }

    /**
     * 频道新增
     */
    @PostMapping
    @ApiOperation(value = "新增频道",notes = "author:lyd")
    @ApiImplicitParam(name = "channel", value = "新增对象", required = true,dataType = "WmChannel")
    public ResponseResult insertWmChannel(@RequestBody WmChannel channel){
        return wmChannelService.saveWmChannel(channel);
    }

    @PutMapping
    @ApiOperation(value = "修改频道",notes = "author:lyd")
    @ApiImplicitParam(name = "channel", value = "修改对象", required = true,dataType = "WmChannel")
    public ResponseResult updateWmChannel(@RequestBody WmChannel wmChannel){
        return wmChannelService.updateWmChannel(wmChannel);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除频道",notes = "author:lyd")
    @ApiImplicitParam(name = "id", value = "删除对象", required = true,dataType = "Integer")
    public ResponseResult deleteById(@PathVariable(name = "id") Integer id){
         return wmChannelService.deleteById(id);
    }
}
